package com.sgb.jicai.view.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.jicai.R;
import com.sgb.jicai.entity.JcMyPriceListEntity;
import com.swgk.core.BR;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import java.util.List;

/**
 * 个人中心--我的加盟-需方部分
 */
public class CenterMyJoinXufangAdapter extends BaseRecycleAdapter<JcMyPriceListEntity> {

    private ItemCallBack itemCallBack;

    public CenterMyJoinXufangAdapter(Context context, List<JcMyPriceListEntity> datas) {
        super(context, R.layout.item_center_myjoin_xufang, datas);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        super.onBindViewHolder(holder, position);
        TextView tvExit = holder.getItem().findViewById(R.id.tv_exit);
        TextView tvReedit = holder.getItem().findViewById(R.id.tv_reedit);
        TextView tvDelete = holder.getItem().findViewById(R.id.tv_delete);
        //我的加盟--退出加盟
        tvExit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != itemCallBack) {
                    itemCallBack.exit(datas.get(position));
                }
            }
        });
        //我的加盟--修改加盟
        tvReedit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != itemCallBack) {
                    itemCallBack.reedit(datas.get(position));
                }
            }
        });
        //我的加盟--删除加盟
        tvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != itemCallBack) {
                    itemCallBack.Delete(datas.get(position));
                }
            }
        });
    }

    @Override
    public void convert(ItemViewHolder holder, final JcMyPriceListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView tvGroupBuyType = holder.getItem().findViewById(R.id.tv_group_buy_type);
        TextView tvTwoType =  holder.getItem().findViewById(R.id.tv_two_type);
        TextView tvQualifyType =  holder.getItem().findViewById(R.id.tv_quotation_type);
        TextView tvJoinType =  holder.getItem().findViewById(R.id.tv_join_type);
        ImageView stateImg = holder.getItem().findViewById(R.id.state_img);
        TextView tvExit = holder.getItem().findViewById(R.id.tv_exit);
        TextView tvReedit = holder.getItem().findViewById(R.id.tv_reedit);
        TextView tvDelete = holder.getItem().findViewById(R.id.tv_delete);

        if ("1".equals(entity.getStatus()) || "5".equals(entity.getStatus())) { // 1.集采中 5.加盟中
            tvExit.setVisibility(View.VISIBLE);
            tvReedit.setVisibility(View.VISIBLE);
            tvDelete.setVisibility(View.GONE);
        } else {
            tvExit.setVisibility(View.GONE);
            tvReedit.setVisibility(View.GONE);
            tvDelete.setVisibility(View.VISIBLE);
        }
         switch (entity.getGroupbuyType()) {//集采类型: 1即报集采 2 汇总集采  3.企业专项
            case "1":
                tvGroupBuyType.setText("即报即采");
                tvGroupBuyType.setBackgroundResource(R.drawable.shape_blue_button);
                break;
            case "2":
                tvGroupBuyType.setText("汇集采购");
                tvGroupBuyType.setBackgroundResource(R.drawable.shape_yellow_button);
                break;
            case "3":
                tvGroupBuyType.setText("企业专项");
                tvGroupBuyType.setBackgroundResource(R.mipmap.qyzx);
                break;
            default:
                tvGroupBuyType.setVisibility(View.GONE);
                break;
        }
        switch (entity.getStatus()) {//状态  1 进行中2 已完成  3集采作废   4集采失败  5 加盟中 6 报价中
            case "1":
                stateImg.setImageResource(R.mipmap.collect_ing);
                break;
            case "2":
                stateImg.setImageResource(R.mipmap.collect_complate);
                break;
            case "3":
                stateImg.setImageResource(R.mipmap.jc_jczf);
                break;
            case "4":
                stateImg.setImageResource(R.drawable.collect_fail);
                break;
            case "5":
                stateImg.setImageResource(R.mipmap.jc_to_join);
                break;
            case "6":
                stateImg.setImageResource(R.mipmap.jc_bjz);
                break;
        }
        switch (entity.getGroupbuyClass()) {//报价类型: 0：市场报价   1：会员报价
            case "1":
                tvTwoType.setVisibility(View.VISIBLE);
                tvTwoType.setText("商品材料");
                tvTwoType.setBackgroundResource(R.drawable.shape_blue_button);
                break;
            case "2":
                tvTwoType.setVisibility(View.VISIBLE);
                tvTwoType.setText("机械租赁");
                tvTwoType.setBackgroundResource(R.drawable.shape_blue_button);
                break;
            case "3":
                tvTwoType.setVisibility(View.VISIBLE);
                tvTwoType.setText("设备租赁");
                tvTwoType.setBackgroundResource(R.drawable.shape_blue_button);
                break;
            default:
                tvTwoType.setVisibility(View.GONE);
                break;
        }
        switch (entity.getOfferType()) {//报价类型: 2：市场报价   1：会员报价
            case "1":
                tvQualifyType.setVisibility(View.VISIBLE);
                tvQualifyType.setText("客户报价");
                tvQualifyType.setTextColor(context.getResources().getColor(R.color.color_FDA72D));
                tvQualifyType.setBackgroundResource(R.drawable.bg_market_join_price);
                break;
            case "2":
                tvQualifyType.setVisibility(View.VISIBLE);
                tvQualifyType.setTextColor(context.getResources().getColor(R.color.color_0286DF));
                tvQualifyType.setText("市场报价");
                tvQualifyType.setBackgroundResource(R.drawable.bg_marketprice);
                break;
            case "3":
                tvQualifyType.setVisibility(View.VISIBLE);
                tvQualifyType.setTextColor(context.getResources().getColor(R.color.color_FF4B10));
                tvQualifyType.setText("成员报价");
                tvQualifyType.setBackgroundResource(R.drawable.bg_memberoffer);
                break;
            default:
                tvQualifyType.setVisibility(View.GONE);
                break;
        }
        switch (entity.getJoinType()) {//1、市场加盟 2、会员加盟 3、成员加盟
            case "1":
                tvJoinType.setVisibility(View.VISIBLE);
                tvJoinType.setTextColor(context.getResources().getColor(R.color.color_FDA72D));
                tvJoinType.setText("客户加盟");
                tvJoinType.setBackgroundResource(R.drawable.bg_market_join_price);

                break;
            case "2":
                tvJoinType.setVisibility(View.VISIBLE);
                tvJoinType.setText("市场加盟");
                tvJoinType.setTextColor(context.getResources().getColor(R.color.color_0286DF));
                tvJoinType.setBackgroundResource(R.drawable.bg_marketprice);
                break;
            case "3":
                tvJoinType.setVisibility(View.VISIBLE);
                tvJoinType.setTextColor(context.getResources().getColor(R.color.color_FF4B10));
                tvJoinType.setText("成员加盟");
                tvJoinType.setBackgroundResource(R.drawable.bg_memberoffer);
                break;
            default:
                tvJoinType.setVisibility(View.GONE);
                break;
        }



    }

    public void setItemCallBack(ItemCallBack itemCallBack) {
        this.itemCallBack = itemCallBack;

    }

    public interface ItemCallBack {

        void exit(JcMyPriceListEntity entity);

        void reedit(JcMyPriceListEntity entity);

        void Delete(JcMyPriceListEntity entity);
    }
}
